package java_collection.lab;

import java.util.LinkedHashSet;
import java.util.Set;

// java FindDups i came i saw i left
// boolean add(E e), return false If this set already contains the element
//  LinkedHashSet stores its elements in a hash table, with a linked list running through it,
// orders its elements based on the order in which they were inserted into the set (insertion-order)
// LinkedHashSet spares its clients from the unspecified,
// generally chaotic ordering provided by HashSet at a cost that is only slightly higher.

public class FindDups2 {

	public static void main(String[] args) {
		String para = "i came i saw i left";
		String[] word = para.split(" ");
		
		Set<String> s = new  LinkedHashSet<String>();
        for (String a : word)
            if (!s.add(a))
                System.out.println("Duplicate detected: " + a);

        System.out.println(s.size() + " distinct words: " + s);

	}

}

/*
 * Duplicate detected: i
*  Duplicate detected: i
*  4 distinct words: [i, came, saw, left]
 */
